import 'bootstrap/dist/css/bootstrap.css';
import '../css/style.scss';
import 'bootstrap/dist/js/bootstrap.js';
require('./common.js');
var Fingerprint = require('./fingerprint.js');
import {config,qrcode,productList,queryOrder_new,buyOrder_new,log} from './urlconfig/config.js';
$('.nav-all a[href="course.html"]').addClass('active');
var token;
if(localStorage.token != null){
    token=localStorage.token;
    key()
}
function getCpuid(){
    if(localStorage.cpuid==null){
        cpuid=Math.random();
        localStorage.setItem("cpuid",cpuid);
        return cpuid
    }else{
        cpuid=localStorage.getItem("cpuid");
        return cpuid
    }
}
var cpuid = new Fingerprint().get();
var edition='web_1.5.1.2';
var channel;
var sys='Window10';
function GetUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");

    if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;

        for (var i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");

            if (arr != null && arr[0] == paraName) {
                return arr[1];
            }
        }
        return "";
    }
    else {
        return "";
    }
};
(function (){
    var url = document.location.toString();
    if (url.indexOf("?") != -1) {
        channel=GetUrlParam("c_code");
        localStorage.setItem("channel",channel);
    }else{
        if(localStorage.channel !=null){
            channel=localStorage.getItem("channel");
        }else{
            channel='plat_a01';
        }
    }
})();
function key(){
    $.ajax({
        type:'post',
        url:buyOrder_new,
        dataType:'json',
        data:{
            token:token,
        },
        success:function (res){
            if(res.code === 200) {
                $('.course-bottom-title').empty();
                $(".key-all").css("padding","20px 100px");
                var arr=res.data.orderList;
                $.each(arr,function(i,item){
                    var item=$('<div class="col-sm-3"><p> '+name(item.product_title)+'</p></div>'+
                        '<div class="col-sm-6"><p>激活码 : '+item.secretkey+'</p></div>'+
                        '<div class="col-sm-3"><p>时间 : ' +timestampToTime(item.pay_time)+'</p></div>');
                    $("#keys").append(item);
                })

            }else{

            }
        },
        error:function (err){

        }
    })
}

    $(".close-btn").click(function (){
        $(".close-office").show();
    });
    $(".quxiao").click(function (){
        $(".close-office").hide();
    });



/*更改版本为中文*/
function name(name){
    if(name=="office365_personal"){
        name="Office 365 个人版";
        return name;
    }else if(name=="office2016_family"){
        name="Office 365 家庭和学生版";
        return name;
    }else if(name=="office365_family"){
        name="Office 365 家庭版";
        return name;
    }else if(name=="office365_major"){
        name="Office 365 专业增强版";
        return name;
    }else if(name=="office365_family_split"){
        name="Office 365 家庭分拆版";
        return name;
    }
    else if(name=="office2016_family_for_mac"){
        name="Office 2016 for mac";
        return name;
    }else{
        name="Office 365";
    }

}
/*获取时间*/
function timestampToTime(timestamp) {
    var date = new Date(timestamp * 1000),
    Y = date.getFullYear() + '-',
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-',
    D = date.getDate() + ' ',
    h = date.getHours() + ':',
    m = date.getMinutes() + ':',
    s = date.getSeconds();
    return Y+M+D+h+m+s;
}
var main=$("#fagepage").val();
$(".swiper-slide a").click(function(){
    var btn=$(this).attr("data-log");
    $.ajax({
        type:'GET',
        url:log+main+'/'+ btn +'/'+ channel+'/'+ edition + '/'+ sys + '/'+cpuid,
        dataType: 'json',
        success:function(res) {
            if(res.code==200){

            }
        },
        error:function() {

        }
    })
});

var main=$("#fagepage").val();
$.ajax({
    type:'GET',
    url:log+ main+'/'+'pageShow' +'/'+ channel+'/'+ edition + '/'+ sys + '/'+cpuid,
    dataType: 'json',
    success:function(res) {
        if(res.code==200){

        }
    },
    error:function(err) {

    }
});
$(".course-bottom a").click(function(){
    var btn=$(this).attr("data-log");
    $.ajax({
        type:'GET',
        url:log+ btn +'/'+ channel+'/'+ edition + '/'+cpuid,
        dataType: 'json',
        success:function(res) {
            if(res.code==200){

            }
        },
        error:function(err) {

        }
    })
});
$(".help").click(function (){
    if('Widget' in window){
        Widget.slotOpenExternalBrowser('http://office.zhuazi.com/pc.html');
    }
});
require('./model.js');